package pl.vanta.mjuzik2;

import java.util.Random;
import java.util.Set;

import pl.vanta.utils.commons.ArraysUtils;

public class Shuffler
{
	private static Random	random	= new Random(System.currentTimeMillis());

	public static int getWeightRandom(int[] weights)
	{
		int sum = ArraysUtils.sum(weights);
		int rand = random.nextInt(sum);
		int pick = 0;

		for (int k = 0; k <= rand; pick++)
		{
			k += weights[pick];
		}

		return pick - 1;
	}

	public static int getRandom(int toNumber)
	{
		return random.nextInt(toNumber);
	}

	public static int getRandomIn(int[] in)
	{
		return in[random.nextInt(in.length)];
	}

	public static int getRandomNotIn(int toNumber, Set<Integer> notIn)
	{
		int i = -1;

		do
		{
			i = random.nextInt(toNumber);
		}
		while (notIn.contains(i));

		return i;
	}

	public static int getRandomNotIn(int toNumber, int[] notIn)
	{
		int i = -1;

		do
		{
			i = random.nextInt(toNumber);
		}
		while (ArraysUtils.contains(notIn, i));

		return i;
	}
}